<?php
class MenuAction extends AdminAction {
    //资源目录管理列表
	public function index(){
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		$cate = M('Category');
		$map['catepid'] = 0;
		$list = $cate->where($map)->select();
		$this->assign("list",$list);
		$this->display();
	}
	
	//添加资源库
	public function addmenu(){
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		$cate = D('Category');
		if(strtolower($_SERVER['REQUEST_METHOD']) == 'post')
		{
			$cond = $_POST;
			$cond['cateppid'] = 0;
			$cond['_column'] = array('catename','engname','catepid','remark','status','order');
			foreach ($cond['_column'] as $one) $data[$one] = trim($cond[$one]);
			
			if($cate->create($data))
			{
				if(($uid = $cate->add()) != false)
				{
					$this->redirect('Menu/index');
				}
			}else
			{
				$this->assign('erorsta','1');
				$this->assign('error',$cate->getError());
			}
		}
		$this->display();
	}
	
	//删除资源库
	public function dele()
	{
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		$cateid = $_POST['cateid'];
		
		if($cateid)
		{
			$map['cateid'] = $cateid;
			$res = M('Category')->where($map)->delete();
			if($res) echo 1;
			else echo 0;	
		}
		else echo 0;
	} 
}

?>